<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        html,
        body,
        #container {
            width: 100%;
            height: 100%;
        }
    </style>
</head>

<body>
    <div id="container"></div>
    <script type="text/javascript">
        window._AMapSecurityConfig = {
            securityJsCode: "6f648721779dbcbf05b2a65993889ff4",
        };
    </script>
    <script src="https://webapi.amap.com/loader.js"></script>
    <script type="text/javascript">
        AMapLoader.load({
            key: "635c069122b3e0123584f542c1701c27", //申请好的Web端开发者 Key，调用 load 时必填
            version: "2.0", //指定要加载的 JS API 的版本，缺省时默认为 1.4.15
        })
            .then((AMap) => {
                const map = new AMap.Map("container");
                const marker = new AMap.Marker({
                    position: [110.39, 39.9], //位置
                });
                const infoWindow = new AMap.InfoWindow({
                    //创建信息窗体
                    isCustom: true, //使用自定义窗体
                    content: "<div>我胡汉三又回来了!!!</div>", //信息窗体的内容可以是任意html片段
                    offset: new AMap.Pixel(30, -45),
                });
                const onMarkerClick = function (e) {
                    infoWindow.open(map, e.target.getPosition()); //打开信息窗体
                    //e.target就是被点击的Marker
                };
                const mar = new AMap.Marker({
                    position: [116.481181, 39.989792],
                });
                const lineArr = [
                    [116.368904, 39.913423],
                    [116.382122, 39.901176],
                    [116.387271, 39.912501],
                    [114.398258, 39.904600]
                ];
                const polyline = new AMap.Polyline({
                    path: lineArr, //设置线覆盖物路径
                    strokeColor: "red", //线颜色
                    strokeWeight: 5, //线宽
                    strokeStyle: "solid", //线样式
                });
                map.add(polyline);
                marker.on("click", onMarkerClick); //绑定click事件
                map.add(marker); //添加到地图
            })
            .catch((e) => {
                console.error(e); //加载错误提示
            });
    </script>
</body>

</html>